<?php 
/**
 *   This file is part of GeoArticle (a Joomla plugin).
 *   Written by Ivar Bergman (www.ivarbergman.se)
 *   Copyright (c) 2010 Ivar Bergman. All rights reserved.
 *
 *   GeoArticle is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   GeoArticle is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with GeoArticle.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

defined('_JEXEC') or die('Restricted access'); 
JHTML::_('behavior.tooltip'); 


$db     =& JFactory::getDBO();
$user     =& JFactory::getUser();
$nullDate   = $db->getNullDate();

$now    =& JFactory::getDate();

// Set toolbar items for the page
JToolBarHelper::title(   JText::_( 'GeoArticle Tag Manager' ), 'generic.png' );
JToolBarHelper::publishList('publish');
JToolBarHelper::unpublishList('unpublish');
JToolBarHelper::deleteList('Are you sure you want to remove the selected categories?','remove');
JToolBarHelper::editListX('edit');
JToolBarHelper::addNewX('add');
JToolBarHelper::preferences( 'com_geoarticle','400');

$ordering = ($this->lists['order'] == 'ga.ordering');

$filter_on = $mainframe->getUserStateFromRequest( $option.'filter_order', 'filter_order', 'category', 'cmd' );
$search    = $mainframe->getUserStateFromRequest( $option.'search',       'search',       '',         'string' );
?>
<form action="index.php" method="post" name="adminForm">
<table>
<tr>
  <td align="left" width="100%">
    <?php echo JText::_( 'Filter' ); ?>:
    <input type="text" name="search" id="search" value="<?php echo $this->lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
    <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
    <button onclick="document.getElementById('search').value='';this.form.getElementById('filter_catid').value='0';this.form.getElementById('filter_state').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
  </td>
  <td nowrap="nowrap">
    <?php echo $this->lists['state']; ?>
  </td>
</tr>
</table>
<div id="editcell">
  <table class="adminlist">
  <thead>
    <tr>
      <th width="5">
        <?php echo JText::_( 'Num' ); ?>
      </th>
      <th width="20">
        <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
      </th>
      <th class="title">
        <?php echo JHTML::_('grid.sort',   'Title', 'ga.title', $this->lists['order_Dir'], $this->lists['order'] ); ?>
      </th>
      <th width="10%" nowrap="nowrap">
        <?php echo JHTML::_('grid.sort',   'Published', 'ga.state', $this->lists['order_Dir'], $this->lists['order'] ); ?>
      </th>
      <th width="80" nowrap="nowrap">
        <?php echo JHTML::_('grid.sort',   'Order', 'ga.ordering', $this->lists['order_Dir'], $this->lists['order'] ); ?>
      </th>
      <th width="10%" class="title">
        <?php echo JHTML::_('grid.sort',   'Author', 'author', $this->lists['order_Dir'], $this->lists['order'] ); ?>
      </th>
      <th width="5%" nowrap="nowrap">
         <?php echo JHTML::_('grid.sort',  'Created On', 'ga.created', $this->lists['order_Dir'], $this->lists['order'] ); ?>
      </th>
      
    </tr>
  </thead>
  <tfoot>
    <tr>
      <td colspan="7">
        <?php $this->pagination->getListFooter(); ?>
      </td>
    </tr>
  </tfoot>
  <tbody>
  <?php
  $k = 0;
  for ($i=0, $n=count( $this->items ); $i < $n; $i++)
  {
    $row = &$this->items[$i];

    $link = JRoute::_( 'index.php?option=com_geoarticle&task=edit&cid[]='. $row->id );
    
    $checked  = JHTML::_('grid.checkedout',   $row, $i );
    
    if ( $row->state == 1 ) {
      $img = 'tick.png';
      $alt = JText::_( 'Published' );
    } else if ( $row->state == 0 ) {
      $img = 'publish_x.png';
      $alt = JText::_( 'Unpublished' );
    } else if ( $row->state == -1 ) {
      $img = 'disabled.png';
      $alt = JText::_( 'Archived' );
    }
    ?>
    <tr class="<?php echo "row$k"; ?>">
      <td>
        <?php echo $this->pagination->getRowOffset( $i ); ?>
      </td>      
      <td>
        <?php echo $checked; ?>
      </td>
      <? // Title ?>
      <td>
        <?php
        if (  JTable::isCheckedOut($user->get ('id'), $row->checked_out ) ) {
          echo $row->title;
        } else {
          ?>
          <span class="editlinktip hasTip" title="<?php echo JText::_( 'Edit Tag' );?>::<?php echo $row->title; ?>">
          <a href="<?php echo $link; ?>">
            <?php echo $row->title; ?></a></span>
          <?php
        }
        ?>
      </td>
      <? // Publish ?>
      <td align="center">
        <span class="editlinktip">
        <a href="javascript:void(0);" onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $row->state ? 'unpublish' : 'publish' ?>')">
        <img src="images/<?php echo $img;?>" width="16" height="16" border="0" alt="<?php echo $alt;?>" /></a></span>
      </td>
      <? // Order ?>
      <td class="order">
        <span><?php echo $this->pagination->orderUpIcon( $i, true, 'orderup', 'Move Up', $ordering ); ?></span>
        <span><?php echo $this->pagination->orderDownIcon( $i, $n, true, 'orderdown', 'Move Down', $ordering ); ?></span>
        <?php echo $row->ordering;?>
      </td>
      <? // Author ?>
      <td>
        <?php echo  $row->author; ?>
      </td>
      <? // Created ?>
      <td align="center">
        <?php echo JHTML::_('date',  $row->created, JText::_('DATE_FORMAT_LC4') ); ?>
      </td>
    </tr>
    <?php
    $k = 1 - $k;
  }
  ?>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="7">
        <?php echo $this->pagination->getListFooter(); ?>
      </td>
    </tr>
  </tfoot>
  </table>
</div>

  <input type="hidden" name="option" value="com_geoarticle" />
  <input type="hidden" name="task" value="view" />
  <input type="hidden" name="boxchecked" value="0" />
  <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
  <input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
  <?php echo JHTML::_( 'form.token' ); ?>
</form>
